//Singleton
var Controller = new function()
{
	this.view = null;
	this.model = null;

	this.Init = function()
	{
		this.view = View;
		this.model = Model;
		this.model.Init("XML|JSON|GEARS:location:[user:pass]");

		this.model.Init("XML|JSON|GEARS:location:[user:pass]");
		// alert(this.model.DataSource)

	}

	this.PerformCommand = function(src, command)
	{
		comm = this.ParseCommand(command);
		switch (comm.type)
		{
		case 'page':
			if (comm.action == 'show')
			{
				//alert(ret.query)
				data = "";
				data = Model.GetData(ret.query)
				this.ShowPage(comm.id, comm.where, data);

			}

			break;

		default:
			break;
		}

	}

	this.ShowPage = function(id, where, data)
	{
		var content = this.view.Display('page_' + id, data);// {'sex':'zzzzzzzzzzzzzz23'})
		$(where).replaceWith(content)
	}

	this.ParseCommand = function(command)
	{
		///show|delete:body:page|object:id|name:query
		// / show:page:1
		// / show:object:object1
		// / delete:object:object1

		comm = command.split(':');
		ret = new Object();
		ret.action = comm[0];
		ret.where = comm[1];
		ret.type = comm[2];
		ret.id = comm[3];
		ret.query = comm[4];

		return ret;
	}
}
